package SpringBoot.spring_boot_starter_websocket.D02_服务端广播.config;

import java.security.Principal;
import java.util.HashMap;
import java.util.Map;

import org.springframework.context.ApplicationListener;
import org.springframework.messaging.Message;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.web.socket.messaging.SessionConnectedEvent;

import com.titan.core.utils.io.ConsoleUtils;

/**
 *
 *
 * @author 周成功
 *
 */
public class WebSocketSessionConnectedEvent implements ApplicationListener<SessionConnectedEvent> {
    public static Map<String, Principal> users = new HashMap<String,Principal>();
    
    
    @Override
    public void onApplicationEvent(SessionConnectedEvent event) {
        StompHeaderAccessor headers = StompHeaderAccessor.wrap(event.getMessage()); //获取消息头
//        System.out.println(headers);
//        System.out.println(headers.getMessageHeaders());
//        List<String> items = headers.getNativeHeader("login");
        ConsoleUtils.log("WebSocketSessionConnectedEvent", "headers", headers.getMessageHeaders().toString());
        ConsoleUtils.log("WebSocketSessionConnectedEvent", "simpConnectMessage", headers.getHeader("simpConnectMessage"));
        ConsoleUtils.print("WebSocketSessionConnectedEvent", headers.getMessageHeaders().keySet());
        
        Message message = (Message)headers.getHeader("simpConnectMessage");
        ConsoleUtils.log("WebSocketSessionConnectedEvent", "items", message.getHeaders());
        ConsoleUtils.log("WebSocketSessionConnectedEvent", "items", message.getHeaders().get("nativeHeaders"));
        Map map = (Map)message.getHeaders().get("nativeHeaders");
//        List list = (List)map.get("login");
//        ConsoleUtils.log("WebSocketSessionConnectedEvent", "login", list.get(0));
//        users.put(name, headers.getUser());
    }

}
